
<template>
  <div class="userList">
    <searchForm :keys="['username','name']" ref="searchForm" @on-search="onSearch"></searchForm>
    <div class="table">
      <el-table
          :header-cell-style="{background:'#F8F9FA'}"
          v-loading="loading"
          :height="'calc(100% - 0px)'"
          :data="tableData">
        <el-table-column
            prop=""
            width="120"
            label="">
        </el-table-column>
        <el-table-column
            prop="name"
            label="姓名">
        </el-table-column>
        <el-table-column
            label="用户名"
            prop="username">
        </el-table-column>
        <el-table-column
            label="所属机构"
            prop="orgName">
        </el-table-column>
        <el-table-column
            label="操作"
            width="240"
            prop="caozuo">
          <template slot-scope="scope">
            <editUserBtn :params="scope.row" @after-op="afterOp"></editUserBtn>
<!--            <el-button type="warning" size="small" @click="goSetP(scope.row)">重置密码</el-button>-->
<!--            <el-button type="danger" size="small" @click="goDelete(scope.row)">删除</el-button>-->
            <!--            <el-button type="danger" :disabled="scope.row.isBinding ==2" size="small" @click="openClock(scope.row)">解除绑定</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination :page="pageInfo.page" :pageSize="pageInfo.pageSize" :total="pageInfo.total"  @handleSizeChange="pageSizeChange"
                @pageChange="pageChange"></pagination>
    <el-dialog
        title="重置密码"
        :visible.sync="dialogVisiblep"
        :destroy-on-close="true"
        :close-on-click-modal="false"
        width="500px">
      <passwordForm ref="passwordForm"></passwordForm>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisiblep=false">取 消</el-button>
    <el-button type="primary" @click="resetPSW">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import searchForm from "../../../../components/searchForm";
import pagination from "../../../../components/pagination";
import passwordForm from "./passwordForm";
import dict from "../../../../util/dict";
import editUserBtn from "@/views/systemManage/user/module/editUserBtn";
export default {
  name: "userList",
  components:{
    searchForm,
    pagination,
    passwordForm,
    editUserBtn
  },
  methods:{
    afterOp(){
      this.getUserByCriteria()
    },
    openClock(row){
      this.$confirm('此操作将解除绑定, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.unbindUsers({id:row.id}).then(res=>{
          this.$message.success('操作成功')
          this.getUserByCriteria();
        })
      }).catch(() => {
      });
    },
    onSearch(){
      this.pageInfo.page = 1;
      this.getUserByCriteria();
    },
    goSetP(row){
      this.dialogVisiblep = true
      this.$nextTick(()=>{
        this.$refs.passwordForm.form.id = row.id
        this.$refs.passwordForm.form.username = row.username
      })
    },
    resetPSW(){
      this.$refs.passwordForm.validate().then(res=>{
        let params = {
          id: this.$refs.passwordForm.form.id,
          password: this.$refs.passwordForm.form.password,
        }
        this.$api.resetPSW(params).then(res=>{
          this.$message.success('重置成功')
          this.dialogVisiblep = false
        })
      })

    },
    goDelete(row) {
      this.$confirm('此操作将删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let params = {id: row.id}
        this.$api.delUsers(params).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getUserByCriteria();
        })
      }).catch(() => {
      });
    },
    pageChange(page){
      this.pageInfo.page = page
      this.getUserByCriteria();
    },
    pageSizeChange(size){
      this.pageInfo.pageSize = size
      this.getUserByCriteria();
    },
    getUserByCriteria(){
      this.loading = true
      let params = {
        page:this.pageInfo.page -1,
        pageSize:this.pageInfo.pageSize,
        username:this.$refs.searchForm.form.username,
        name:this.$refs.searchForm.form.name,
        orgId:this.selectNode.id
      }
      this.$api.getUserByCriteria(params).then(res=>{
        this.loading = false
        this.tableData = res.data.data
        this.pageInfo.total = res.data.recordsTotal
      })
    },
  },
  data() {
    return {
      tableData: [],
      selectNode:{},
      bindingMap:dict.bindingMap,
      dialogVisible:false,
      dialogVisiblep:false,
      loading:false,
      pageInfo:{
        page:1,
        pageSize:10,
        total:0
      }
    }
  }
}
</script>

<style scoped lang="less">
.userList{
  width: calc(100% - 140px);
  height: 100%;
  flex:1;
  .table{
    padding: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 160px);
  }
}
</style>